﻿using System;
using BattleBotsMattAndSunny.Components.Interfaces;
using Robocode;

namespace BattleBotsMattAndSunny.Components.Treads
{
    public class BasicTreads : ITreadsManager
    {
        public IDataManager dataManager { get; set; }

        public AdvancedRobot robot { get; set; }

        public BasicTreads(IDataManager dm, AdvancedRobot r)
        {
            dataManager = dm;
            robot = r;
        }

        public void OnHitByBullet(HitByBulletEvent e)
        {
        }

        public void OnScannedRobot(ScannedRobotEvent e)
        {
            var random = new Random();
            var randomDirection = random.Next(1, 2);
            if (randomDirection == 1)
                robot.SetTurnRight(e.Bearing + 60);
            else
                robot.SetTurnLeft(e.Bearing + 60);
            robot.SetAhead(e.Distance / 4);
        }

        public void OnHitWall(HitWallEvent e)
        {
            //robot.SetBack(30);
        }

        public void Move()
        {
            if (robot.TurnRemaining > 0) return;
            var random = new Random();
            var randomAngle = random.Next(1, 360) - 180;

            robot.SetTurnRight(randomAngle);
            robot.SetAhead(robot.BattleFieldHeight / 4);
        }
    }
}